<template>
    <h1>登录页面</h1>

    <table>
        <tr>
            <td>用户名:</td>
            <td>
                <input type="text" v-model="Name" >
            </td>
        </tr>

        <tr>
            <td>密码：</td>
            <td>
                <input type="password" v-model="Pwd" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="UserLogin">
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">

import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter();

const Name =ref('');
const Pwd = ref('');

const UserLogin =() =>{
    axios({
        method: 'get',
        url: 'http://localhost:64202/api/User/UserLogin',
        params: {
            name: Name.value,
            pwd: Pwd.value
        }
    })
    .then(function(res){
        if(res.data!=null){
            console.log(res.data);
            alert('登录成功');
            router.push({
                name:'UserInfoAdd',
                params:{
                    U_Id:res.data[0].U_Id
                }
            })
        }
        else{
            console.log('登录失败');
        }
    })
}

</script>
